Imports System.Data.SharePointClient
Module Module1
    Public Sub Main()
        TestUpdate()
    End Sub

    Public Sub TestUpdate()
        Dim factory As NHibernate.ISessionFactory = New NHibernate.Cfg.Configuration().Configure().BuildSessionFactory()
        Dim session As NHibernate.ISession = factory.OpenSession()
        Dim query As NHibernate.IQuery = session.CreateQuery("FROM Test")
        Dim list As IList(Of Test)
        list = query.List(Of Test)()
        list.Item(0).Body = "Test"
        session.Save(list.Item(0))
        session.Flush()
        session.Close()
    End Sub
    Public Sub TestHQL()
        Dim factory As NHibernate.ISessionFactory = New NHibernate.Cfg.Configuration().Configure().BuildSessionFactory()

        Dim session As NHibernate.ISession = factory.OpenSession()
        Dim query As NHibernate.IQuery = session.CreateQuery("FROM Test as T WHERE (T.MyID=1 or T.MyID=2) or (T.MyID=3) ORDER BY T.MyID ASC")
        Dim list As IList
        List = query.List()

    End Sub

    Public Sub TestHQLAggregate()
        Dim factory As NHibernate.ISessionFactory = New NHibernate.Cfg.Configuration().Configure().BuildSessionFactory()

        Dim session As NHibernate.ISession = factory.OpenSession()
        Dim query As NHibernate.IQuery = session.CreateQuery("select max(T.MyID) FROM Test as T WHERE (T.MyID=1 or T.MyID=2) or (T.MyID=3) ORDER BY T.MyID ASC")
        Dim list As IList
        list = query.List()

    End Sub

    Public Sub TestSearch()
        Dim cfg As New NHibernate.Cfg.Configuration()
        cfg = cfg.Configure()
        Dim factory As NHibernate.ISessionFactory = cfg.BuildSessionFactory()
        Dim nSession As NHibernate.ISession = factory.OpenSession()
        Dim session As NHibernate.Search.IFullTextSession = NHibernate.Search.Search.CreateFullTextSession(nSession)

        Dim parser As New Lucene.Net.QueryParsers.QueryParser("id", New Lucene.Net.Analysis.Standard.StandardAnalyzer())
        Dim query As Lucene.Net.Search.Query = parser.Parse("pie")
        Dim q As NHibernate.IQuery = session.CreateQuery("from Test") ' 
        Dim result As IList = q.List()
        Dim SearchFactory As NHibernate.Search.Engine.SearchFactory = NHibernate.Search.Engine.SearchFactory.GetSearchFactory(cfg)
        For Each obj As Test In result
            SearchFactory.PerformWork(obj, obj.MyID, session.GetSessionImplementation(), Search.Backend.WorkType.Add)
        Next

        q = session.CreateFullTextQuery(query, GetType(Test))
        result = q.List

    End Sub
    Public Sub TestSQLView()
        Dim commandText = "select test0_.ID as ID0_, test0_.Body as Body0_ from Announcements.Brian test0_  where ((test0_.ID=1 )or(test0_.ID=2 ))or((test0_.ID=3 )) order by  test0_.ID ASC"
        Dim cmd As New Command
        Dim con As New SharePointClient.Connection
        cmd.CommandText = commandText
        cmd.Connection = con
        Dim dr As IDataReader
        dr = cmd.ExecuteReader()

    End Sub
    Public Sub TestSQL()
        Dim commandText = "select test0_.ID as ID0_, test0_.Body as Body0_ from Announcements test0_ where ((test0_.ID=1 )or(test0_.ID=2 ))or((test0_.ID=3 )) order by  test0_.ID ASC"
        Dim cmd As New Command
        Dim con As New SharePointClient.Connection
        cmd.CommandText = commandText
        cmd.Connection = con
        Dim dr As IDataReader
        dr = cmd.ExecuteReader()
        dr.Read()

    End Sub
    Public Sub TestGroupBY()
        Dim commandText = "select Top 100 * from Announcements test0_ where ((ID=4) or (ID=3)) GROUP BY ID, FRED"
        Dim cmd As New Command
        Dim con As New SharePointClient.Connection()
        cmd.CommandText = commandText
        cmd.Connection = con
        Dim dr As IDataReader
        dr = cmd.ExecuteReader()
    End Sub
    Public Sub TestWildCard()
        Dim commandText = "select Top 100 * from Announcements test0_ where ((ID=4) or (ID=3)) GROUP BY ID"
        Dim cmd As New Command
        Dim con As New SharePointClient.Connection()
        cmd.CommandText = commandText
        cmd.Connection = con
        Dim dr As IDataReader
        dr = cmd.ExecuteReader()
    End Sub
End Module
